<template>
    <div>
    
        <div style="visibility:hidden;">
            <div style="float:left">
                <Input style="width:250px">
                <span slot="prepend">学院名称：</span>
                <Button slot="append" icon="ios-search"></Button>
                </Input>
            </div>
    
            <Button-group>
                <Button @click="modal_add_status = true">新增</Button>
                <Button @click="exportData(2)">导出</Button>
            </Button-group>
        </div>
        <Table border stripe :columns="header" :data="data_list" size="small" ref="table" class="table"></Table>
        <Modal v-model="modal_del_status" title="删除一个实际应用" @on-ok="option_delete_save" @on-cancel="modal_cancel">
            <Form :model="temp_dele_data" :label-width="80">
                <p>您确定删除这个记录吗？</p>
            </Form>
        </Modal>
    
    </div>
</template>
<script>
export default {
    data() {
        return {

            //初始化url
            init_url: '/mes/core/app/real/getByIns/list/',
            del_url: '/mes/core/app/real/delete/',

            //表格标题
            header: [
                {
                    type: 'index',
                    width: 50,
                    align: 'center'
                },
                {
                    "title": "学院名称",
                    "key": "instituteName",
                    "width": 120,
                    "sortable": true,
                },
                {
                    "title": "应用名称",
                    "key": "appName",
                    "width": 120,
                    "sortable": true,
                },
                {
                    "title": "创建时间",
                    "key": "createTime",
                    "width": 120,
                    "sortable": true
                },
                {
                    "title": "备注",
                    "key": "remark",
                    "min-width": 120,
                    "sortable": true
                },
                {
                    "title": '操作',
                    "min-width": 150,
                    "align": 'center',
                    render: (h, params) => {
                        return h('div', [
                            h('Button', {
                                props: {
                                    type: 'error',
                                    size: 'small'
                                },
                                on: {
                                    click: () => {
                                        this.delete_show(params)
                                    }
                                }
                            }, '删除')
                        ]);
                    }
                }

            ],
            //表格数据
            data_list: [],
            modal_del_status: false,
            temp_dele_data: {},

        }
    },
    methods: {
        appinit(_self) {
            var _self = this;
            this.$ajax.get(_self.init_url + _self.insId)
                .then(function (response) {
                    _self.data_list = response.data.data;
                    _self.data_cache_list = _self.data_list.slice();
                })
                .catch(function (error) {
                    console.log(error);
                });
        },
        delete_show(params) {
            this.modal_del_status = true;
            this.temp_dele_data = params.row;
        },
        modal_cancel() {
            this.$Message.info("操作取消");
        },
        option_delete_save() {
            var _self = this;
            var func = this.appinit;
            this.$Message.info("操作确认");
            this.$ajax.post(_self.del_url + _self.temp_dele_data.id, )
                .then(function (response) {
                    if (response) {
                        if (response.data.status == 'success') {
                            _self.$Message.info('删除成功');
                            func(_self);
                            return;
                        }
                    }
                    _self.$Message.info('删除失败');
                })
                .catch(function (error) {
                    console.log(error);
                    _self.$Message.info('删除失败');
                });
        },
        appint() {
            var _self = this;
            //初始化表单数据
            this.$ajax.get(_self.init_url + _self.insId)
                .then(function (response) {
                    _self.data_list = response.data.data;
                })
                .catch(function (error) {
                    console.log(error);
                });
        },
    },
    mounted() {


    },
    props: ['insId'],
    watch: {
        insId: function (newValue, oldValue) {
            var _self = this;

            //初始化表单数据
            this.$ajax.get(_self.init_url + newValue)
                .then(function (response) {
                    _self.data_list = response.data.data;
                })
                .catch(function (error) {
                    console.log(error);
                });
        }
    }
}
</script>

<style>
.btn-group {
    margin-bottom: 5px;
}
</style>
